package com.chineseall.rebirth.bridge.util;

import javax.servlet.http.HttpServletRequest;

import jmind.core.cache.xmemcached.Memcached;
import jmind.core.util.CookieUtil;
import jmind.core.util.DataUtil;
import jmind.resource.manager.ZKMemcachedManager;

public class XMemcached {

    /** 用户接口在缓存中的标志 **/
    public static final String API_SNS_FLAG = "api_";
    /****SNS CONNECTION 连接*******/
    public static final String SNS_CONNECTION = "sns_";

    public static final String CAPTCHA = "captcha_";
    /******广告投放 sns缓存******/
    public static final String SNS_FREE_TRY = "snsft_";

    public static final String OPENPLATFORM_CODE = "open_code_";
    public static final String OPENPLATFORM_TOKEN = "open_t_";

    private static final Memcached cache = ZKMemcachedManager.getInstance().getResource("common");

    public static final Memcached getCache() {
        return cache;
    }

    public static String getFansKey(int bookId, int uid) {
        return "fans-" + bookId + "-" + uid;
    }

    public static String getCaptcha(final HttpServletRequest request) {
        String uuid = CookieUtil.getUUIDCookie(request);
        if (DataUtil.isEmpty(uuid))
            return DataUtil.EMPTY;
        return cache.get(CAPTCHA + uuid);
    }

}
